package com.qf.mybatis.jdbc;

import com.qf.mybatis.entity.User;

import java.sql.*;

public class JdbcDemo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/text?useUnicode=true&characterEncoding=utf8&&useSSL=false";

        //2.创建链接对象
        Connection connection = DriverManager.getConnection(url, "root", "root");

        //3.创建PreStatment对象
        String sql = "select * from t_users where id > ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1,1);

        //4.执行
        ResultSet rs = preparedStatement.executeQuery();

        //5.遍历结果集
        while (rs.next()) {
            //手工ORM
            User user = new User();
            user.setId(rs.getInt("id"));
            user.setName(rs.getString("name"));
            System.out.println(user);
        }

        //6.关闭对象
        rs.close();
        preparedStatement.close();
        connection.close();
    }
}
